function isWiling(arr) {
    if (arr.length < 2) return arr.length
    let pre = arr[0] - arr[1];
    let count = pre === 0 ? 1 : 2
    for (let i = 2; i < arr.length; i++) {
        let curr = arr[i - 1] - arr[i];
        if ((pre >= 0 && curr < 0) || (pre <= 0 && curr > 0)) {
            count++;
            pre = curr
        }
    }
    return count;
}